package com.tengju.bff.interfaces.manage.crm.brand.assembler;

import com.tengju.bff.interfaces.manage.crm.brand.vo.BrandMarketSortVO;
import com.tengju.bff.interfaces.shared.Formatter;
import com.tengju.data.domain.model.clickhouse.brand.BrandMarketSortInfo;
import com.tengju.data.domain.model.clickhouse.dashboard.MonthQuarterEnum;
import com.tengju.data.domain.shared.DateUtil;
import org.apache.commons.collections.CollectionUtils;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 
 * @Date: 2021/5/10 16:46
 * @Description: 
 */
public class BrandMarketSortAssembler {

    public static List<BrandMarketSortVO> toVOList(Integer dateType,Integer offset,List<BrandMarketSortInfo> infoList) {
        List<BrandMarketSortVO> voList = new ArrayList<>();
        if (CollectionUtils.isEmpty(infoList)) {
            return voList;
        }

        int rank = offset + 1;
        for (BrandMarketSortInfo info : infoList) {
            BrandMarketSortVO vo = new BrandMarketSortVO();
            vo.setBrank(rank);
            vo.setBrandId(info.getBrandId().getValue());
            vo.setBrandName(info.getBrandName() == null ? "" : info.getBrandName());

            //月份维度
            if (dateType == MonthQuarterEnum.CURRENT_MONTH.getCode() || dateType == MonthQuarterEnum.LAST_MONTH.getCode()) {
                vo.setSellAccount(Formatter.commaMoney(info.getMonthGmv()));
                vo.setMakeMembers(info.getMonthDealerMembers() == null ? "0" : Formatter.thousandDecimal(BigDecimal.valueOf(info.getMonthDealerMembers())));
                vo.setHodeRatio(info.getMonthDealerRatio() == null ? "0" : info.getMonthDealerRatio() + "%");
            }
            //季度维度
            if (dateType == MonthQuarterEnum.CURRENT_QUARTER.getCode()) {
                vo.setSellAccount(Formatter.commaMoney(info.getQuarterGmv()));
                vo.setMakeMembers(info.getQuarterDealerMembers() == null ? "0.00" : Formatter.thousandDecimal(BigDecimal.valueOf(info.getQuarterDealerMembers())));
                vo.setHodeRatio(info.getQuarterDealerRatio() == null ? "0" : info.getQuarterDealerRatio() + "%");
            }


            voList.add(vo);
            rank++;

        }
        return voList;
    }

    public static List<BrandMarketSortVO> toExportVOList(Integer dateType,List<BrandMarketSortInfo> infoList) {
        List<BrandMarketSortVO> voList = new ArrayList<>();
        if (CollectionUtils.isEmpty(infoList)) {
            return voList;
        }

        int rank = 1;
        for (BrandMarketSortInfo info : infoList) {
            BrandMarketSortVO vo = new BrandMarketSortVO();
            vo.setBrank(rank);
            vo.setBrandId(info.getBrandId().getValue());
            vo.setBrandName(info.getBrandName() == null ? "" : info.getBrandName());

            //月份维度
            if (dateType == MonthQuarterEnum.CURRENT_MONTH.getCode() || dateType == MonthQuarterEnum.LAST_MONTH.getCode()) {
                vo.setSellAccount(info.getMonthGmv() == null ? "0" : info.getMonthGmv().toString());
                vo.setMakeMembers(info.getMonthDealerMembers() == null ? "0" : String.valueOf(info.getMonthDealerMembers()));
                vo.setHodeRatio(info.getMonthDealerRatio() == null ? "0" : info.getMonthDealerRatio() + "%");
            }
            //季度维度
            if (dateType == MonthQuarterEnum.CURRENT_QUARTER.getCode()) {
                vo.setSellAccount(info.getQuarterGmv() == null ? "0" : info.getQuarterGmv().toString());
                vo.setMakeMembers(info.getQuarterDealerMembers() == null ? "0" : String.valueOf(info.getQuarterDealerMembers()));
                vo.setHodeRatio(info.getQuarterDealerRatio() == null ? "0" : info.getQuarterDealerRatio() + "%");
            }


            voList.add(vo);
            rank++;

        }
        return voList;
    }


}
